﻿using System;
using System.Data.SqlClient;
using umbraco;
using System.Xml;

namespace TheOutfield.UmbExt.DocTypeExtensions.UserControls
{
    public partial class DocTypeExtensionsInstaller : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InstallLanguageString();
        }

        protected void InstallLanguageString()
        {
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath("/umbraco/config/lang/en.xml"));

            XmlNode node = document.SelectSingleNode("/language/area[@alias='actions']");

            if (node.SelectNodes("/key[@alias='swapmasterdoctype']").Count == 0)
            {
                XmlNode newChild = document.CreateElement("key");

                XmlAttribute attribute = document.CreateAttribute("alias");
                attribute.Value = "swapmasterdoctype";
                newChild.Attributes.Append(attribute);

                newChild.InnerText = "Swap Master Doc Type";

                node.AppendChild(newChild);

                document.Save(base.Server.MapPath("/umbraco/config/lang/en.xml"));
            }

            if (node.SelectNodes("/key[@alias='extractmasterdoctype']").Count == 0)
            {
                XmlNode newChild = document.CreateElement("key");

                XmlAttribute attribute = document.CreateAttribute("alias");
                attribute.Value = "extractmasterdoctype";
                newChild.Attributes.Append(attribute);

                newChild.InnerText = "Extract Master Doc Type";

                node.AppendChild(newChild);

                document.Save(base.Server.MapPath("/umbraco/config/lang/en.xml"));
            }
        }
    }
}